package com.zx.controller;

import com.zx.bean.Manager;
import com.zx.dto.AjaxJson;
import com.zx.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller("/ManagerController")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    //定义一个添加接口
    @PostMapping("/addManager")
    public String addManager(Manager manager){
        return "add";
    }

    //定义一个删除接口
    @PostMapping("/delManager")
    public String delManager(int id){
        managerService.delManager(id);
        return "del";
    }

    //定义一个修改的接口
    @PostMapping("/updateManager")
    public String updateManager(int id){
        managerService.updateManager(id);
        return "updateManager";
    }

    //定义一个查询单个的接口
    @PostMapping("/findOneManager")
    @ResponseBody
    public AjaxJson findOneManager(int id){
        AjaxJson ajaxJson = new AjaxJson();
        Manager manager = managerService.findOneManager(id);
        ajaxJson.put("manager",manager);
        return ajaxJson;
    }

    //定义一个查询全部的接口
    @PostMapping("/findAllManager")
    @ResponseBody
    public AjaxJson findAllManager(){
        AjaxJson ajaxJson = new AjaxJson();
        managerService.findAllManager();
        return ajaxJson;
    }
}
